<?php

namespace app\common\controller;

use think\Cache;
use think\Controller;
use think\Db;
use think\Session;

class HomeBase extends Controller
{


    protected $wx_config;

    protected function _initialize()
    {
        parent::_initialize();

        $this->getWxConfig();

        $this->assign('version','11');

//        if (isset($_GET['user_id'])) {
//            $user_info = Db::name('user')->where(['id' => $_GET['user_id']])->find();
//
//            $user_token = Db::name('mb_user_token')->where(['user_id' => $user_info['id']])->find();
//
//            $user_info = [
//                'user_id' => $user_info['id'],
//                'user_name' => $user_info['username'],
//                'user_nick' => $user_info['user_nick'],
//                'user_uuid' => $user_info['user_uuid'],
//                'token' => $user_token['token']
//            ];
//            Session::set('user_info', $user_info);
//        }

//            $user_token = Db::name('mb_user_token')->where(['user_id' => $user_info['id']])->find();
//
//            $user_info = [
//                'user_id' => $user_info['id'],
//                'user_name' => $user_info['username'],
//                'user_nick' => $user_info['user_nick'],
//                'user_uuid' => $user_info['user_uuid'],
//                'token' => $user_token['token']
//            ];
//            Session::set('user_info', $user_info);
//        }


        $user_info = Session::get('user_info');
        if (empty($user_info)) {
            $this->redirect('index/user/index');
        } else {
            $user_info['token'] = $user_info['user_token'];
        }

        $this->assign('user', $user_info);


    }

    /**
     * 获取站点信息
     */
    /*    protected function getSystem()
        {
            if (Cache::has('site_config')) {
                $site_config = Cache::get('site_config');
            } else {
                $site_config = Db::name('setting')->field('value')->where('name', 'site_config')->find();
                $site_config = unserialize($site_config['value']);
                Cache::set('site_config', $site_config);
            }

            $this->assign($site_config);
        }*/

    protected function getWxConfig()
    {
        if (Cache::has('wx_config')) {
            $wx_config = Cache::get('wx_config');
        } else {
            $wx_config = Db::name('system')->field('value')->where('name', 'wx_config')->find();
            $wx_config = json_decode($wx_config['value'], true);
            Cache::set('wx_config', $wx_config);
        }
        $this->wx_config = $wx_config;
    }



}